﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Runtime.Serialization;

namespace Effects.Effects
{
    /// <summary>
    /// Represents one change in effects settings. 
    /// </summary>
    /// <remarks>
    /// <para>
    ///  This class is used as event arguments in <see cref="Effect.SettingsChanged"/> event.
    ///  Key specifies paramater fo effect that is changed and value it's new value.
    ///  It is created by effect which understands the meaning of key and value properties. Therefore they are both object, so any type can passed to the constructor.
    ///  </para>
    ///  <para>
    ///   Class is serializable, beacause changes migh be saved and loaded.
    ///  </para>
    /// </remarks>
    /// <example>
    ///   <code>
    ///   // member of some class
    ///   //key for depth parameter
    ///    private const int depthKey=0;
    ///      
    ///    //later in some method we somehow count new value of depth parameter
    ///    double depthValue = // get it somehow
    ///    EffectSettingsChangedEventArgs settingsChange = new EffectSettingsChangedEventArgs(depthKey,depthValue);
    ///  
    ///    
    ///    // later on, we might get EffectSettingsChangedEventArgs back
    ///    EffectSettingsChangedEventArgs settings = // get it from somewhere 
    ///    int key = (int) settings.Key;
    ///    if(key == depthKey)
    ///    {
    ///          double depthValue = (double) settings.Value;
    ///    }
    ///   </code>
    /// </example>
    [Serializable()]
    public class EffectSettingsChangedEventArgs:EventArgs,ISerializable
    {
        /// <summary>
        ///  Specifies parameter of effect that has changed.
        /// </summary>
        private object key;
        /// <summary>
        ///  Gets the key.
        /// </summary>
        public object Key
        {
            get { return key; }
        }

        /// <summary>
        ///  Specifies value of the parameter after change.
        /// </summary>
        private object value;
        /// <summary>
        ///  Gets value of the parameter that have changed.
        /// </summary>
        public object Value
        {
            get { return value; }
        }

        /// <summary>
        ///  Creates new instace with given key and value.
        /// </summary>
        /// <param name="key"> Key that specifies parameter </param>
        /// <param name="value"> Value of the parameter </param>
        public EffectSettingsChangedEventArgs(object key, object value)
        {
            this.key=key;
            this.value=value;
        }

        /// <summary>
        ///  Deserialization constructor. ISerializable interface implementation.
        /// </summary>
        public EffectSettingsChangedEventArgs(SerializationInfo info, StreamingContext context)
        {
            this.key = info.GetValue("Key", typeof(object));
            this.value = info.GetValue("Value", typeof(object));
        }

        /// <summary>
        ///  Serialization method.
        /// </summary>
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("Key", key);
            info.AddValue("Value", value);
        }
    }
}
